03.b - GitHub-App-Installation-Flow
Relevant source files
Purpose and ScopeLink copied!
This document describes the GitHub App installation process that occurs after payment completion. It covers the user-facing installation interface, repository selection options, permission requests, and the technical mechanisms that capture the installation_id for downstream processing.
For the OAuth initiation that triggers this flow, see GitHub OAuth Initiation. For handling the OAuth callback after installation, see OAuth Callback Handler.
Installation Flow OverviewLink copied!
The GitHub App installation is a two-phase process that bridges payment completion to repository access provisioning. Unlike standard OAuth flows, GitHub Apps require users to explicitly install the app on their account and select which repositories to grant access to before OAuth authorization begins.
Complete Installation SequenceLink copied!
Sources: app/success/page.tsx L54-L59
app/api/auth/github/setup/route.ts L4-L67
User-Facing InterfaceLink copied!
Success Page Installation PromptLink copied!
After completing Stripe payment, users land on /success with a session_id query parameter. This page serves as the gateway to GitHub App installation, with critical messaging about repository selection.
Success Page Component Structure
| Element | Purpose | Implementation |
|---|---|---|
| Video Tutorial | 15-second visual guide | Hosted at cdn.vibecoders.school |
| Warning Banner | Emphasizes "Only select repositories" | Amber-styled alert box |
| Connect Button | Initiates GitHub App flow | Links to /api/auth/github?session_id=xxx |
| Session Persistence | Carries payment context | session_id URL parameter |
The success page implements a crucial educational step, displaying an auto-playing video that demonstrates the installation process visually. This reduces user error during repository selection.
Sources: app/success/page.tsx L10-L71
Sources: app/success/page.tsx L38-L53
Repository Selection: Critical Security DecisionLink copied!
The GitHub App installation UI presents users with two mutually exclusive options for repository access. This choice is user-controlled, not app-controlled, and has significant security implications.
Repository Access OptionsLink copied!
| Option | Scope | Risk Level | Recommendation |
|---|---|---|---|
| All repositories | Current + future repos | High | ❌ Not recommended |
| Only select repositories | User-specified list | Low | ✅ Recommended |
Why "Only Select Repositories" MattersLink copied!
The system architecture emphasizes repository selection restriction for three reasons:
- Minimal Access Principle: Users only need to grant access to the repository they want documented
- Future Repository Protection: "All repositories" includes repositories created after installation
- Blast Radius Limitation: If credentials are compromised, only selected repositories are exposed
The warning messaging appears in three locations:
- Success page banner app/success/page.tsx L38-L40
- GitHub App description github-app-description.md L9
- README documentation README.md L123-L145
Sources: app/success/page.tsx L38-L40
github-app-description.md L1-L46
Permissions and ScopeLink copied!
GitHub App PermissionsLink copied!
The GitHub App requests minimal read-only permissions to fulfill its repository access provisioning purpose:
Sources: README.md L130-L135
Permission JustificationsLink copied!
| Permission | Purpose | Used In |
|---|---|---|
Contents: Read | Clone repository files for documentation | Automation scripts |
Metadata: Read | Retrieve repository name, owner, visibility | API calls |
Email addresses: Read | Identify customer for repository naming | Repository creation |
read:user | Fetch GitHub username | OAuth callback |
user:email | Retrieve user email address | Customer correlation |
Note that all permissions are read-only. The app never requests write access to repositories, ensuring it cannot modify customer code.
Sources: README.md L128-L136
app/api/auth/github/setup/route.ts L59
Technical Installation FlowLink copied!
GitHub App Installation URL ConstructionLink copied!
When users click "Connect GitHub" on the success page, they are redirected to a GitHub-hosted installation interface. The URL follows this pattern:
https://github.com/apps/{GITHUB_APP_SLUG}/installations/new?state={state_token}
The GITHUB_APP_SLUG environment variable determines which GitHub App to install. For production, this is godeepwiki-github-integration.
Sources: app/success/page.tsx L54
Installation ID GenerationLink copied!
When a user completes app installation, GitHub generates a unique installation_id that represents the relationship between the user's account and the installed app. This ID is permanent and survives across reinstallations unless the user explicitly uninstalls the app.
Sources: app/api/auth/github/setup/route.ts L4-L67
Setup Callback HandlerLink copied!
The /api/auth/github/setup route serves as an intermediary between GitHub App installation and OAuth authorization. This route captures the installation_id and bridges the two-phase authentication process.
Route Handler ImplementationLink copied!
// /api/auth/github/setup/route.tsexport async function GET(request: NextRequest)
The handler performs these operations in sequence:
- Extract Parameters app/api/auth/github/setup/route.ts L5-L10 *
installation_id: The newly created installation identifier *setup_action: Either'install'or'update'*state: Optional state token for CSRF protection - Validate Installation ID app/api/auth/github/setup/route.ts L13-L18 * Returns 400 error if
installation_idis missing * This prevents the flow from continuing without proper installation - Store Installation ID in Cookie app/api/auth/github/setup/route.ts L21-L28 * Cookie name:
github_installation_id* Attributes:httpOnly,sameSite: 'lax',maxAge: 600(10 minutes) * The cookie persists the installation ID for the OAuth callback handler - Preserve State Token app/api/auth/github/setup/route.ts L31-L39 * If GitHub provided a state token, store it in
github_oauth_statecookie * Otherwise, generate a new state token usingcrypto.randomUUID() - Construct OAuth URL app/api/auth/github/setup/route.ts L54-L62 * Builds authorization URL with
client_id,redirect_uri,state, andscope* Redirects user to GitHub OAuth authorization screen
Sources: app/api/auth/github/setup/route.ts L1-L67
Cookie Storage StrategyLink copied!
The 10-minute expiration window is sufficient for the OAuth flow while minimizing the risk of cookie hijacking. The httpOnly flag prevents client-side JavaScript from accessing these security-sensitive cookies.
Sources: app/api/auth/github/setup/route.ts L22-L38
Setup Action TypesLink copied!
GitHub sends a setup_action parameter indicating the installation context:
| Value | Meaning | Occurrence |
|---|---|---|
install | First-time installation | User installs app for the first time |
update | Permission or repository update | User modifies existing installation |
The system logs this action app/api/auth/github/setup/route.ts L64
but treats both cases identically in the flow. Both result in storing the installation_id and redirecting to OAuth.
Sources: app/api/auth/github/setup/route.ts L9-L64
Security ConsiderationsLink copied!
CSRF Protection via State ParameterLink copied!
The state token serves as CSRF protection during the OAuth flow. The setup handler either preserves GitHub's state or generates a new one:
const oauthState = state || crypto.randomUUID();
This state is stored in a cookie and verified in the OAuth callback handler to ensure the authorization response matches the original request.
Sources: app/api/auth/github/setup/route.ts L52
app/api/auth/github/setup/route.ts L32-L38
Cookie Security AttributesLink copied!
All authentication cookies use these security attributes:
| Attribute | Value | Purpose |
|---|---|---|
httpOnly | true | Prevents XSS attacks |
secure | true (production only) | Enforces HTTPS in production |
sameSite | 'lax' | Prevents CSRF while allowing redirects |
maxAge | 600 seconds | 10-minute expiration window |
path | '/' | Available to all routes |
The secure flag is conditionally applied based on NODE_ENV to support local development over HTTP.
Sources: app/api/auth/github/setup/route.ts L23-L27
app/api/auth/github/setup/route.ts L33-L37
Repository Access LimitationsLink copied!
The emphasis on "Only select repositories" throughout the UI is a defense-in-depth strategy:
- User Education: Video tutorial + warning banner on success page
- Documentation: GitHub App description field includes explicit warning
- README: Installation guide recommends specific repository selection
Even if the app's permissions are read-only, limiting the number of accessible repositories reduces the attack surface if the system is compromised.
Sources: app/success/page.tsx L38-L52
github-app-description.md L9-L11
Relationship to OAuth CallbackLink copied!
The setup callback handler bridges the gap between app installation and OAuth authorization. The installation_id stored in cookies during this phase is critical for the OAuth callback handler, which retrieves it to link payment (via session_id) to repository access (via installation_id).
The flow continues in the OAuth callback handler, documented in OAuth Callback Handler, which:
- Retrieves the
installation_idfrom the cookie - Exchanges the OAuth code for an access token
- Logs the correlation between
session_idandinstallation_id - Sends notifications to trigger automation
Sources: app/api/auth/github/setup/route.ts L21-L28
Common Installation IssuesLink copied!
Missing Installation ID ErrorLink copied!
If the setup callback receives a request without an installation_id parameter, it returns:
{ "error": "Missing installation_id parameter" }
This typically indicates that the user cancelled the installation or that the GitHub App configuration is incorrect.
Sources: app/api/auth/github/setup/route.ts L14-L18
GitHub Client ID Not ConfiguredLink copied!
If GITHUB_CLIENT_ID is missing from environment variables, the setup handler returns:
{ "error": "GitHub client ID not configured" }
This prevents the OAuth redirect from constructing an invalid authorization URL.
Sources: app/api/auth/github/setup/route.ts L43-L49
Debugging Installation FlowLink copied!
The setup handler logs installation completion:
console.log(`[GitHub Setup] Installation ${installationId} completed (${setupAction}), redirecting to OAuth...`);
This log entry appears in Vercel logs and helps correlate installation attempts with subsequent OAuth callbacks.
Sources: app/api/auth/github/setup/route.ts L64
Refresh this wiki
Last indexed: 23 November 2025 (922b35)
On this page
- GitHub App Installation Flow
- Purpose and Scope
- Installation Flow Overview
- Complete Installation Sequence
- User-Facing Interface
- Success Page Installation Prompt
- Repository Selection: Critical Security Decision
- Repository Access Options
- Why "Only Select Repositories" Matters
- Permissions and Scope
- GitHub App Permissions
- Permission Justifications
- Technical Installation Flow
- GitHub App Installation URL Construction
- Installation ID Generation
- Setup Callback Handler
- Route Handler Implementation
- Cookie Storage Strategy
- Setup Action Types
- Security Considerations
- CSRF Protection via State Parameter
- Cookie Security Attributes
- Repository Access Limitations
- Relationship to OAuth Callback
- Common Installation Issues
- Missing Installation ID Error
- GitHub Client ID Not Configured
- Debugging Installation Flow
Ask Devin about godeep.wiki-jb